#[get("/task_list?<p>")]
fn task_list(p: usize, cookies: Cookies, state: State<MySqlDriver>) -> Response<'static> {
    let mut res = Response::new();
    res.set_header(ContentType::HTML);

    let user_info: UserInfo = get_cookies(&cookies);
    if user_info.id == 0 {
        let html: String = format!("您未登录，请先<a href=\"{}login\">登录</a>", state.base_url.as_str());
        res.set_sized_body(Cursor::new(html));
        return res;
    }

    // mod_id: String, 
    // mod_menu_open: String, 
    // sub_mod_id: String, 
    // page_title: String, 
    // title: String
    let header: String = get_header(
        "task-mod".to_string(), 
        "task-mod-menu-open".to_string(), 
        String::new(),
        "用户后台 - 任务列表".to_string(), 
        "任务列表".to_string(), &cookies,
        &state);

    let pool_result: Result<Pool, mysql::Error> = Pool::new(state.driver.as_str());
    let pool: Pool;
    if let Ok(p) = pool_result {
        pool = p;
    } else {
        res.set_sized_body(Cursor::new("无法建立数据库连接".to_string()));
        return res;
    }
    let conn_result: Result<PooledConn, mysql::Error> = pool.get_conn();
    let mut conn: PooledConn;
    if let Ok(c) = conn_result {
        conn = c;
    } else {
        res.set_sized_body(Cursor::new("无法获取数据库连接".to_string()));
        return res;
    }
    let mut sql: String = format!("SELECT COUNT(`id`) AS `count` FROM `copywrite_order` WHERE `get_user_id` = {} AND `status` = 1", user_info.id);
    let row: Row = conn.query_first(sql.clone()).unwrap().unwrap();
    let count: usize = from_row(row);
    let max_page: usize = ceil((count / 10) as f64, 0) as usize;
    let skip_number: usize = (p - 1) * 10;

    sql = format!("SELECT `co`.`id`, `t`.`movie_name` AS `topic_id`, `t`.`bt_file`, `co`.`requirement`, `t`.`type` AS `topic_type` FROM `copywrite_order` AS `co` INNER JOIN `topic` AS `t` ON `t`.`id` = `co`.`topic_id` WHERE `co`.`status` = 1 AND `co`.`get_user_id` = {} ORDER BY `co`.`id` ASC LIMIT {}, 10", user_info.id, skip_number);
    let rows1: Vec<Row> = conn.query(sql.clone()).unwrap();
    let mut copywrite_html: String = String::new();
    for row1 in rows1 {
        let (id, topic_id, bt_file, requirement, topic_type): (usize, String, String, String, String) = from_row(row1);
        let bt_file_hostr: HoString = HoString::copy_string(bt_file);
        let bt_file_array: Vec<HoString> = bt_file_hostr.split_str("|");
        let mut bt_file_first: HoString = HoString::new();
        if let Some(file) = bt_file_array.get(0) {
            bt_file_first = file.clone();
        }
        copywrite_html.push_str(format!("<tr>\
                                      <th scope=\"row\">{}</th>\
                                      <td>{}</td>\
                                      <td>{}</td>\
                                      <td>{}</td>\
                                      <td><a target=\"_blank\" href=\"{}uploads/{}\">下载</a></td>\
                                      <td>\
                                        <a class=\"btn btn-primary\" href=\"{}view_copywrite_task?id={}\">查看</a>\
                                      </td>\
                                </tr>", id, topic_type.as_str(), topic_id.as_str(), requirement.as_str(), state.base_url.as_str(), bt_file_first.to_str(), state.base_url.as_str(), id).as_str());
    }

    let mut clip_require: String = String::new();
    let row: Option<Row> = conn.query_first("SELECT `global_value` FROM `global_var` WHERE `global_key` = 'clip_requirement' LIMIT 1").unwrap();
    if let Some(r) = row {
        clip_require = from_row(r);
    }
    let rows2: Vec<Row> = conn.query(format!("SELECT `clip_o`.`id`, `t`.`movie_name` AS `topic_id`, `t`.`bt_file`, `t`.`type` AS `topic_type` FROM `clip_order` AS `clip_o` INNER JOIN `topic` AS `t` ON `t`.`id` = `clip_o`.`topic_id` WHERE `clip_o`.`status` = 1 AND `clip_o`.`get_user_id` = {} ORDER BY `clip_o`.`id` ASC LIMIT {}, 10", user_info.id, skip_number).as_str()).unwrap();
    let mut clip_html: String = String::new();
    for row2 in rows2 {
        let (id, topic_id, bt_file, topic_type): (usize, String, String, String) = from_row(row2);
        let bt_file_hostr: HoString = HoString::copy_string(bt_file);
        let bt_file_array: Vec<HoString> = bt_file_hostr.split_str("|");
        let mut bt_file_first: HoString = HoString::new();
        if let Some(file) = bt_file_array.get(0) {
            bt_file_first = file.clone();
        }
        clip_html.push_str(format!("<tr>\
                                      <th scope=\"row\">{}</th>\
                                      <td>{}</td>\
                                      <td>{}</td>\
                                      <td>{}</td>\
                                      <td><a target=\"_blank\" href=\"{}uploads/bt_file/{}\">下载</a></td>\
                                      <td>\
                                        <a class=\"btn btn-primary\" href=\"{}view_clip_task?id={}\">查看</a>\
                                      </td>\
                                    </tr>", id, topic_type.as_str(), topic_id.as_str(), clip_require.as_str(), state.base_url.as_str(), bt_file_first.to_str(), state.base_url.as_str(), id).as_str());
    }
    
    let mut is_prev_disabled: String = String::new();
    let mut is_next_disabled: String = String::new();
    if p <= 1 {
        is_prev_disabled.push_str(" disabled");
    }
    if p >= max_page {
        is_next_disabled.push_str(" disabled");
    }
    let mut nav: String = format!("<nav>\
                                    <ul class=\"pagination justify-content-center\">\
                                        <li class=\"page-item{}\">\
                                            <a class=\"page-link\" href=\"task_list?p={}\" aria-label=\"Previous\">\
                                                <span aria-hidden=\"true\">&laquo;</span>\
                                            </a>\
                                        </li>", is_prev_disabled.as_str(), p - 1);
    for i in 1..=max_page {
        if p == i {
            nav.push_str(format!("<li class=\"page-item active\"><a class=\"page-link\" href=\"javascript:void(0);\">{}</a></li>", i).as_str());
        } else {
            nav.push_str(format!("<li class=\"page-item\"><a class=\"page-link\" href=\"task_list?p={}\">{}</a></li>", i, i).as_str());
        }
    }
    nav.push_str(format!("<li class=\"page-item{}\">\
                            <a class=\"page-link\" href=\"task_list?p={}\" aria-label=\"Next\">\
                                <span aria-hidden=\"true\">&raquo;</span>\
                            </a>\
                          </li>\
                      </ul>\
                    </nav>", is_next_disabled.as_str(), p + 1).as_str());

    let mut src_vec: Vec<&[u8]> = Vec::new();
    let mut replace_vec: Vec<&[u8]> = Vec::new();

    let skip_number_str: String = skip_number.to_string();
    let footer_string: String = get_footer();
    src_vec.push("{header}".as_bytes());
    src_vec.push("{base_url}".as_bytes());
    src_vec.push("{copywrite_html}".as_bytes());
    src_vec.push("{clip_html}".as_bytes());
    src_vec.push("{clip_require}".as_bytes());
    src_vec.push("{skip_number}".as_bytes());
    src_vec.push("{nav}".as_bytes());
    src_vec.push("{footer}".as_bytes());
    replace_vec.push(header.as_bytes());
    replace_vec.push(state.base_url.as_bytes());
    replace_vec.push(copywrite_html.as_bytes());
    replace_vec.push(clip_html.as_bytes());
    replace_vec.push(clip_require.as_bytes());
    replace_vec.push(skip_number_str.as_bytes());
    replace_vec.push(nav.as_bytes());
    replace_vec.push(footer_string.as_bytes());

    let mut page_str: HoString = HoFile::read_file_bytes("web/task_list.html");
    page_str = page_str.replace_bytes_vec(src_vec, replace_vec);
    let html: String = page_str.to_str().to_string().to_owned();
    res.set_sized_body(Cursor::new(html));
    return res;
}

